package com.platform.api.bzproject.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.platform.api.bzproject.model.WxAdvert;
import com.platform.api.bzproject.service.WxAdvertService;
import com.platform.common.core.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author guoyunfei on 2021/7/11 18:42
 * @className WxAdvertController
 * @description TODO 广告配置
 * @Version 1.0
 * 源码联系微信：2549789059
 */
@Api(tags = "微信流量主信息")
@RestController
@RequestMapping("{appid}/advert")
public class WxAdvertController {

    @Autowired
    private WxAdvertService wxAdvertService;

    @ApiOperation(value = "流量主信息", notes="流量主信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "appid", value = "微信appid", required = true, dataType = "String"),
    })
    @GetMapping("adConfig")
    public Result selectOne(@PathVariable String appid){
        QueryWrapper<WxAdvert> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("appid",appid);

        WxAdvert result = wxAdvertService.getOne(queryWrapper);
        if(null == result){
            return Result.success();
        }
        result.setSwitch_inad(result.getSwitchInad());
        result.setBanner(result.getBannerid());
        return Result.success(result);
    }

    @ApiOperation(value = "微信广告展示信息", notes="微信广告展示信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "appid", value = "微信appid", required = true, dataType = "String"),
            @ApiImplicitParam(name = "adPage", value = "页面名称", required = true, dataType = "String"),
    })
    @GetMapping("getAdPageList")
    public Result getAdPageList(@PathVariable String appid,String adPage){
        Map<String,Object> map = new HashMap<>(6);
        map.put("appid",appid);
        map.put("adPage",adPage);
        List<Map<String, Object>> adList = wxAdvertService.getAdPageList(map);
        return Result.success(adList);
    }

}
